<div id="uploadDiv">
  <div>上传图片</div>
  <?php echo $this->Html->image('loading.gif',array('id'=>'uploading')); ?>
  <form target="uploadframe" action="http://localhost/eaters-website/upload.php" method="POST" id="uploadImage_form" name="uploadImage_form" enctype="multipart/form-data">
    <input name="files" type="file" id="uploadFile" size="10" onchange="fileSubmit();" />
    <img id="preview" src="" style="border:1px solid #eee;"/>
  </form>

  <iframe id="uploadframe" name="uploadframe" width="0" height="0" marginwidth="0" frameborder="0" src="about:blank"></iframe>
</div>
<script type="text/javascript">
function fileSubmit() {
  var D = $('#uploadFile');
  if (!/\.(gif|jpg|png|jpeg)$/i.test(D.val())) {
    alert("请上传jpg、jpeg、gif、png格式的图片。");
  }
  $("#uploading").show();
  var form = document.getElementById('uploadImage_form');
  form.submit();
}

function uploadFinished(url){
  $("#imgPath").val(url);
  $("#preview").attr('src',url);
  $("#uploading").hide();
}

</script> 